package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import static org.jsola.core.example.BaseExample.E_CREATE_USER_ID;
import static org.jsola.core.example.BaseExample.E_MODIFIED_USER_ID;
import static org.jsola.core.example.BaseExample.N_CREATE_USER_ID;
import static org.jsola.core.example.BaseExample.N_MODIFIED_USER_ID;
import static org.jsola.hr.example.OfferInfoExample.E_ATTACHMENT;
import static org.jsola.hr.example.OfferInfoExample.E_COMPANY;
import static org.jsola.hr.example.OfferInfoExample.E_COMPANY_ADDR;
import static org.jsola.hr.example.OfferInfoExample.E_COMPANY_ID;
import static org.jsola.hr.example.OfferInfoExample.E_DEP_ID;
import static org.jsola.hr.example.OfferInfoExample.E_EMAIL;
import static org.jsola.hr.example.OfferInfoExample.E_EMAIL_COPY;
import static org.jsola.hr.example.OfferInfoExample.E_EMAIL_SECRET;
import static org.jsola.hr.example.OfferInfoExample.E_EMPLOY_TYPE;
import static org.jsola.hr.example.OfferInfoExample.E_ENTRY_ADDR;
import static org.jsola.hr.example.OfferInfoExample.E_ENTRY_CONTACT;
import static org.jsola.hr.example.OfferInfoExample.E_ENTRY_DATE_END;
import static org.jsola.hr.example.OfferInfoExample.E_ENTRY_DATE_START;
import static org.jsola.hr.example.OfferInfoExample.E_ENTRY_PHONE;
import static org.jsola.hr.example.OfferInfoExample.E_EXPIRY;
import static org.jsola.hr.example.OfferInfoExample.E_EXPIRY_DATE_END;
import static org.jsola.hr.example.OfferInfoExample.E_EXPIRY_DATE_START;
import static org.jsola.hr.example.OfferInfoExample.E_GENDER;
import static org.jsola.hr.example.OfferInfoExample.E_GMT_CREATE_END;
import static org.jsola.hr.example.OfferInfoExample.E_GMT_CREATE_START;
import static org.jsola.hr.example.OfferInfoExample.E_GMT_MODIFIED_END;
import static org.jsola.hr.example.OfferInfoExample.E_GMT_MODIFIED_START;
import static org.jsola.hr.example.OfferInfoExample.E_HRBP;
import static org.jsola.hr.example.OfferInfoExample.E_INFORMAL_TYPE;
import static org.jsola.hr.example.OfferInfoExample.E_MANAGER_FORM;
import static org.jsola.hr.example.OfferInfoExample.E_NAME;
import static org.jsola.hr.example.OfferInfoExample.E_PHONE;
import static org.jsola.hr.example.OfferInfoExample.E_POSITION_ID;
import static org.jsola.hr.example.OfferInfoExample.E_PROBATION;
import static org.jsola.hr.example.OfferInfoExample.E_RANK;
import static org.jsola.hr.example.OfferInfoExample.E_REGULAR_DATE_END;
import static org.jsola.hr.example.OfferInfoExample.E_REGULAR_DATE_START;
import static org.jsola.hr.example.OfferInfoExample.E_SALARY_BASIC_END;
import static org.jsola.hr.example.OfferInfoExample.E_SALARY_BASIC_START;
import static org.jsola.hr.example.OfferInfoExample.E_SALARY_MODE;
import static org.jsola.hr.example.OfferInfoExample.E_SALARY_REMARK;
import static org.jsola.hr.example.OfferInfoExample.E_STATUS;
import static org.jsola.hr.example.OfferInfoExample.E_SUPERVISOR;
import static org.jsola.hr.example.OfferInfoExample.E_WORK_CITY;
import static org.jsola.hr.example.OfferInfoExample.E_WORK_CITY_ID;
import static org.jsola.hr.example.OfferInfoExample.N_ATTACHMENT;
import static org.jsola.hr.example.OfferInfoExample.N_COMPANY;
import static org.jsola.hr.example.OfferInfoExample.N_COMPANY_ADDR;
import static org.jsola.hr.example.OfferInfoExample.N_COMPANY_ID;
import static org.jsola.hr.example.OfferInfoExample.N_DEP_ID;
import static org.jsola.hr.example.OfferInfoExample.N_EMAIL;
import static org.jsola.hr.example.OfferInfoExample.N_EMAIL_COPY;
import static org.jsola.hr.example.OfferInfoExample.N_EMAIL_SECRET;
import static org.jsola.hr.example.OfferInfoExample.N_EMPLOY_TYPE;
import static org.jsola.hr.example.OfferInfoExample.N_ENTRY_ADDR;
import static org.jsola.hr.example.OfferInfoExample.N_ENTRY_CONTACT;
import static org.jsola.hr.example.OfferInfoExample.N_ENTRY_DATE_END;
import static org.jsola.hr.example.OfferInfoExample.N_ENTRY_DATE_START;
import static org.jsola.hr.example.OfferInfoExample.N_ENTRY_PHONE;
import static org.jsola.hr.example.OfferInfoExample.N_EXPIRY;
import static org.jsola.hr.example.OfferInfoExample.N_EXPIRY_DATE_END;
import static org.jsola.hr.example.OfferInfoExample.N_EXPIRY_DATE_START;
import static org.jsola.hr.example.OfferInfoExample.N_GENDER;
import static org.jsola.hr.example.OfferInfoExample.N_GMT_CREATE_END;
import static org.jsola.hr.example.OfferInfoExample.N_GMT_CREATE_START;
import static org.jsola.hr.example.OfferInfoExample.N_GMT_MODIFIED_END;
import static org.jsola.hr.example.OfferInfoExample.N_GMT_MODIFIED_START;
import static org.jsola.hr.example.OfferInfoExample.N_HRBP;
import static org.jsola.hr.example.OfferInfoExample.N_INFORMAL_TYPE;
import static org.jsola.hr.example.OfferInfoExample.N_MANAGER_FORM;
import static org.jsola.hr.example.OfferInfoExample.N_NAME;
import static org.jsola.hr.example.OfferInfoExample.N_PHONE;
import static org.jsola.hr.example.OfferInfoExample.N_POSITION_ID;
import static org.jsola.hr.example.OfferInfoExample.N_PROBATION;
import static org.jsola.hr.example.OfferInfoExample.N_RANK;
import static org.jsola.hr.example.OfferInfoExample.N_REGULAR_DATE_END;
import static org.jsola.hr.example.OfferInfoExample.N_REGULAR_DATE_START;
import static org.jsola.hr.example.OfferInfoExample.N_SALARY_BASIC_END;
import static org.jsola.hr.example.OfferInfoExample.N_SALARY_BASIC_START;
import static org.jsola.hr.example.OfferInfoExample.N_SALARY_MODE;
import static org.jsola.hr.example.OfferInfoExample.N_SALARY_REMARK;
import static org.jsola.hr.example.OfferInfoExample.N_STATUS;
import static org.jsola.hr.example.OfferInfoExample.N_SUPERVISOR;
import static org.jsola.hr.example.OfferInfoExample.N_WORK_CITY;
import static org.jsola.hr.example.OfferInfoExample.N_WORK_CITY_ID;

/**
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class OfferInfoQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_NAME, example = E_NAME)
    @Length(max = 32)
    private String name;

    @ApiParam(value = N_GENDER, example = E_GENDER)
    private Integer gender;

    @ApiParam(value = N_PHONE, example = E_PHONE)
    @Length(max = 11)
    private String phone;

    @ApiParam(value = N_EMAIL, example = E_EMAIL)
    @Length(max = 255)
    private String email;

    @ApiParam(value = N_EMAIL_COPY, example = E_EMAIL_COPY)
    @Length(max = 255)
    private String emailCopy;

    @ApiParam(value = N_EMAIL_SECRET, example = E_EMAIL_SECRET)
    @Length(max = 255)
    private String emailSecret;

    @ApiParam(value = N_EXPIRY, example = E_EXPIRY)
    private Integer expiry;

    /**
     * offer到期时间查询范围
     */
    @ApiParam(value = N_EXPIRY_DATE_START, example = E_EXPIRY_DATE_START)
    private Date expiryDateStart;
    @ApiParam(value = N_EXPIRY_DATE_END, example = E_EXPIRY_DATE_END)
    private Date expiryDateEnd;


    /**
     * 入职时间查询范围
     */
    @ApiParam(value = N_ENTRY_DATE_START, example = E_ENTRY_DATE_START)
    private Date entryDateStart;
    @ApiParam(value = N_ENTRY_DATE_END, example = E_ENTRY_DATE_END)
    private Date entryDateEnd;


    @ApiParam(value = N_EMPLOY_TYPE, example = E_EMPLOY_TYPE)
    private Boolean employType;

    @ApiParam(value = N_INFORMAL_TYPE, example = E_INFORMAL_TYPE)
    private Integer informalType;

    @ApiParam(value = N_PROBATION, example = E_PROBATION)
    private Integer probation;

    /**
     * 转正日期查询范围
     */
    @ApiParam(value = N_REGULAR_DATE_START, example = E_REGULAR_DATE_START)
    private Date regularDateStart;
    @ApiParam(value = N_REGULAR_DATE_END, example = E_REGULAR_DATE_END)
    private Date regularDateEnd;


    @ApiParam(value = N_DEP_ID, example = E_DEP_ID)
    @Length(max = 32)
    private String depId;

    @ApiParam(value = N_POSITION_ID, example = E_POSITION_ID)
    @Length(max = 32)
    private String positionId;

    @ApiParam(value = N_COMPANY, example = E_COMPANY)
    @Length(max = 255)
    private String company;

    @ApiParam(value = N_RANK, example = E_RANK)
    @Length(max = 255)
    private String rank;

    @ApiParam(value = N_HRBP, example = E_HRBP)
    @Length(max = 255)
    private String hrbp;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_SUPERVISOR, example = E_SUPERVISOR)
    @Length(max = 255)
    private String supervisor;

    @ApiParam(value = N_MANAGER_FORM, example = E_MANAGER_FORM)
    private Integer managerForm;

    @ApiParam(value = N_WORK_CITY_ID, example = E_WORK_CITY_ID)
    @Length(max = 32)
    private String workCityId;

    @ApiParam(value = N_WORK_CITY, example = E_WORK_CITY)
    @Length(max = 255)
    private String workCity;

    @ApiParam(value = N_ENTRY_ADDR, example = E_ENTRY_ADDR)
    @Length(max = 255)
    private String entryAddr;

    @ApiParam(value = N_ENTRY_CONTACT, example = E_ENTRY_CONTACT)
    @Length(max = 255)
    private String entryContact;

    @ApiParam(value = N_ENTRY_PHONE, example = E_ENTRY_PHONE)
    @Length(max = 255)
    private String entryPhone;

    @ApiParam(value = N_COMPANY_ADDR, example = E_COMPANY_ADDR)
    @Length(max = 255)
    private String companyAddr;

    @ApiParam(value = N_SALARY_MODE, example = E_SALARY_MODE)
    private Integer salaryMode;

    /**
     * 基本工资查询范围
     */
    @ApiParam(value = N_SALARY_BASIC_START, example = E_SALARY_BASIC_START)
    private Integer salaryBasicStart;
    @ApiParam(value = N_SALARY_BASIC_END, example = E_SALARY_BASIC_END)
    private Integer salaryBasicEnd;


    @ApiParam(value = N_SALARY_REMARK, example = E_SALARY_REMARK)
    @Length(max = 255)
    private String salaryRemark;

    @ApiParam(value = N_ATTACHMENT, example = E_ATTACHMENT)
    @Length(max = 32)
    private String attachment;

    @ApiParam(value = N_STATUS, example = E_STATUS)
    private Integer status;

    /**
     * 创建时间查询范围
     */
    @ApiParam(value = N_GMT_CREATE_START, example = E_GMT_CREATE_START)
    private Date gmtCreateStart;
    @ApiParam(value = N_GMT_CREATE_END, example = E_GMT_CREATE_END)
    private Date gmtCreateEnd;


    @ApiParam(value = N_CREATE_USER_ID, example = E_CREATE_USER_ID)
    @Length(max = 32)
    private String createUserId;

    /**
     * 修改时间查询范围
     */
    @ApiParam(value = N_GMT_MODIFIED_START, example = E_GMT_MODIFIED_START)
    private Date gmtModifiedStart;
    @ApiParam(value = N_GMT_MODIFIED_END, example = E_GMT_MODIFIED_END)
    private Date gmtModifiedEnd;


    @ApiParam(value = N_MODIFIED_USER_ID, example = E_MODIFIED_USER_ID)
    @Length(max = 32)
    private String modifiedUserId;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public OfferInfoQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

